package LecoLi.Util.Item02;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.demo.R;

import java.util.List;

/**
 * Created by Le Co on 2017/5/11.
 */

public class GridAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private String [] names;
    private int [] datas;

    public GridAdapter(Context context, String[] names,int [] datas){
        inflater = LayoutInflater.from(context);
        this.names=names;
        this.datas=datas;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        TextView name;
        TextView value;
        if (view==null){
            view = inflater.inflate(R.layout.leco_item_02_item,null);
        }
        name = (TextView) view.findViewById(R.id.leco_item_02_item_name);
        value = (TextView) view.findViewById(R.id.leco_item_02_item_value);
        name.setText(""+names[i]);
        value.setText(""+datas[i]);
        if (datas[i]>50){
            view.setBackgroundColor(Color.RED);
        }else{
            view.setBackgroundColor(Color.GRAY);
        }
        return view;
    }

    static class ViewHoled{
        TextView name;
        TextView value;
    }
}
